home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-03 | 4.8 KB | 142 lines | [TEXT/MPS ] |
- (*------------------------------------------------------------------------------
- #
- # Macintosh Developer Technical Support
- #
- # EditText Sample Control Panel Device
- #
- # EditCDEV
- #
- # EditCDEV.p - Pascal Source
- #
- # Copyright © 1988 Apple Computer, Inc.
- # All rights reserved.
- #
- # Versions: 1.0 8/88
- #
- # Components: EditCDEV.p August 1, 1988
- # EditCDEV.r August 1, 1988
- # EditCDEV.make August 1, 1988
- #
- # EditCDEV is a sample Control Panel device (cdev) that
- # demonstrates the usage of the edit-related messages.
- # EditCDEV demonstrates how to implement an editText item
- # in a Control Panel Device. It utilizes the new undo, cut, copy,
- # paste, and delete messages that are sent to cdevs in
- # response to user menu selections.
- #
- # It is comprised of two editText items that can be edited
- # and moved between via the mouse or tab key.
- #
- ------------------------------------------------------------------------------*)
-
-
- MODULE EditCDEV;
-
- IMPORT SYSTEM, Types, Memory, Events, Dialogs, Devices;
-
- CONST
-
- textItm = 1; (*first editTExt item in cdev*)
-
- TYPE
-
- CDEVRec = RECORD
- dummyData : INTEGER;
- END;
- (*CDEVPtr = POINTER TO CDEVRec;
- CDEVHnd = HANDLE TO CDEVRec;*)
-
- (*$S Main*) (* put routines in segment "Main"*)
-
- PROCEDURE ^DoEditCommand(message: INTEGER; CPDialog: Dialogs.DialogPtr);
-
- (*$Calling Pascal*)
- PROCEDURE TextCDEV*(message, item, numItems, CPanelID: INTEGER;
- VAR theEvent: Events.EventRecord;
- cdevStorage: Types.Handle;
- CPDialog: Dialogs.DialogPtr) : Types.Handle;
- (*This is the main dispatcher. It must be the first code in the cdev.
- EditCDEV's dispatcher responds only to the following messages from
- the Control Panel:
-
- macDev - To indicate what machines it is available on.
- initDev - To set up some temporary storage and get the caret started.
- keyEvtDev - To check for an edit command and do the appropriate action.
- cutDev - To cut the current selection.
- copyDev - To copy the current selection.
- pasteDev - To paste the contents of the clipboard.
- clearDev - To delete the current selection.
-
- The Dialog Manager's services are used to handle entry of text, selection
- of text, editing of text, and moving between the editText items via the
- tab key. Since the Dialog Manager handles the selection of text, we do not
- have to be concerned with hitDev messages for the editText items. The only
- things we have to take care of are calling the Dialog Manager editing
- routines in response to an edit command, and getting the caret to show up
- at the beginning. In response to an edit command that was the result of
- a command-key equivalent, we must also eliminate the event so that it does
- not get processed as a keyDown by the Dialog Manager. Otherwise, an 'x'
- would show up in the editText item when the user did a command-x to cut
- the text.*)
-
- VAR
- tempChar : CHAR;
- BEGIN
- IF message = Devices.macDev THEN
- RETURN Types.Handle(1) (*we work on every machine*)
- ELSIF cdevStorage # NIL THEN
- CASE message OF
- Devices.initDev: (*initialize cdev*)
- cdevStorage := Memory.NewHandle(SIZE(CDEVRec)); (*create private storage*)
- Dialogs.SelIText(CPDialog, numItems + textItm, 0, 999)| (*make caret show up*)
- Devices.hitDev:|
- Devices.closeDev:|
- Devices.nulDev:|
- Devices.updateDev:|
- Devices.activDev:|
- Devices.deactivDev:|
- Devices.keyEvtDev: (*respond to key down*)
- (*first, get the character*)
- tempChar := CHR(BAND(theEvent.message, Events.charCodeMask));
- (*then see if the command key was down*)
- IF BAND(theEvent.modifiers, Events.cmdKey) # 0 THEN
- message := Devices.nulDev; (*start off with no message*)
- theEvent.what := Events.nullEvent; (*wipe out event*)
- CASE CAP(tempChar) OF (*set appropriate message*)
- 'X': message := Devices.cutDev|
- 'C': message := Devices.copyDev|
- 'V': message := Devices.pasteDev|
- ELSE (* ignore other characters *)
- END;
- DoEditCommand(message, CPDialog); (*let edit command handler take it*)
- END|
- Devices.macDev:|
- Devices.undoDev:|
- Devices.cutDev, Devices.copyDev, Devices.pasteDev, Devices.clearDev:
- DoEditCommand(message, CPDialog)| (*respond to edit command*)
- ELSE (* ignore other messages *)
- END; (*CASE message*)
- RETURN cdevStorage;
- (*if cdevStorage = NIL then ControlPanel will put up memory error*)
- END; (*cdevStorage <> NIL*)
- RETURN NIL
- END TextCDEV;
- (*$Calling Oberon*)
-
- PROCEDURE DoEditCommand (message: INTEGER; CPDialog: Dialogs.DialogPtr);
-
- (*Call the apprpriate Dialog Manager routine to handle an edit command for
- an editText item. It will do all the work regarding the TEScrap.*)
-
- BEGIN
- CASE message OF
- Devices.cutDev: Dialogs.DlgCut(CPDialog)|
- Devices.copyDev: Dialogs.DlgCopy(CPDialog)|
- Devices.pasteDev: Dialogs.DlgPaste(CPDialog)|
- Devices.clearDev: Dialogs.DlgDelete(CPDialog)|
- ELSE (* ignore other messages *)
- END
- END DoEditCommand;
-
- END EditCDEV.
-